package javaTest04.exercise01.processor;

import javaTest04.entity.Person;
import javaTest04.exercise01.annotation.Label;

import java.lang.reflect.Field;

public class PersonDisplay implements PersonAction {
    @Override
    public Person process(Person person) {//展示信息
        Label personLabel = person.getClass().getAnnotation(Label.class);
        if (personLabel == null)
            return null;

        System.out.println("-----------------------");
        System.out.println("种族:" + personLabel.value());
        Field[] fields = person.getClass().getDeclaredFields();

        try {
            for (Field field : fields) {
                if (field.isAnnotationPresent(Label.class)) {
                    field.setAccessible(true);
                    System.out.println(field.getAnnotation(Label.class).value() + ":" + field.get(person));
                }
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException();
        }

        return person;
    }
}
